<template>
  <div class="open-light-chart"></div>
</template>
<script setup>
import * as echarts from "echarts";
import resize from "@/utils/resize";
let chart = ref(null);

const value = 80;
const rate = Math.round((value * 100) / 100);
let option = {
  backgroundColor: "#022552",
  title: {
    text: value + "%",
    textStyle: {
      color: "#fff",
      fontSize: 24,
    },
    itemGap: 10,
    left: "center",
    top: "center",
  },
  tooltip: {
    backgroundColor: "rgba(11, 48, 89, 0.95)",
    borderColor: "#0496FF",
    textStyle: {
      color: "#fff",
    },
    formatter: function (params) {
      return "开灯率" + "：" + params.value + "%";
    },
  },
  polar: {
    center: ["50%", "50%"],
    radius: ["50%", "65%"],
  },
  angleAxis: {
    max: 100,
    show: false,
  },
  radiusAxis: {
    type: "category",
    show: true,
    axisLabel: {
      show: false,
    },
    axisLine: {
      show: false,
    },
    axisTick: {
      show: false,
    },
  },
  series: [
    {
      data: [value],
      name: "",
      type: "bar",
      roundCap: true,
      showBackground: true,
      backgroundStyle: {
        color: "#014B8E",
      },
      coordinateSystem: "polar",
      itemStyle: {
        normal: {
          color: new echarts.graphic.LinearGradient(0, 11, 3, 0, [
            {
              offset: 0,
              color: "#61C8FF",
            },
            {
              offset: 1,
              color: "#61C8FF",
            },
          ]),
        },
      },
    },
  ],
};
onMounted(() => {
  chart.value = echarts.init(document.querySelector(".open-light-chart"));

  resize(chart.value);
  getServerData();
});
let getServerData = () => {
  chart.value.setOption(option);
};
</script>
<style lang="scss" scoped>
.open-light-chart {
  width: 250px;
  height: 250px;
}
</style>
